package com.craftplay.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.craftplay.model.Unit;

public class UnitSqlProvider {

    public String insertSelective(Unit record) {
        BEGIN();
        INSERT_INTO("unit");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getUserId() != null) {
            VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getKind() != null) {
            VALUES("kind", "#{kind,jdbcType=INTEGER}");
        }
        
        if (record.getTitle() != null) {
            VALUES("title", "#{title,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }
        
        if (record.getImage() != null) {
            VALUES("image", "#{image,jdbcType=VARCHAR}");
        }
        
        if (record.getLatitude() != null) {
            VALUES("latitude", "#{latitude,jdbcType=VARCHAR}");
        }
        
        if (record.getLongitude() != null) {
            VALUES("longitude", "#{longitude,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getAddress() != null) {
            VALUES("address", "#{address,jdbcType=VARCHAR}");
        }
        
        if (record.getScope() != null) {
            VALUES("scope", "#{scope,jdbcType=VARCHAR}");
        }
        
        if (record.getForm() != null) {
            VALUES("form", "#{form,jdbcType=INTEGER}");
        }
        
        if (record.getLeastCourseNum() != null) {
            VALUES("least_course_num", "#{leastCourseNum,jdbcType=INTEGER}");
        }
        
        if (record.getLeastPrice() != null) {
            VALUES("least_price", "#{leastPrice,jdbcType=INTEGER}");
        }
        
        if (record.getPrice() != null) {
            VALUES("price", "#{price,jdbcType=INTEGER}");
        }
        
        if (record.getMaxPerson() != null) {
            VALUES("max_person", "#{maxPerson,jdbcType=INTEGER}");
        }
        
        if (record.getDate() != null) {
            VALUES("date", "#{date,jdbcType=VARCHAR}");
        }
        
        if (record.getTimeLen() != null) {
            VALUES("time_len", "#{timeLen,jdbcType=INTEGER}");
        }
        
        if (record.getTool() != null) {
            VALUES("tool", "#{tool,jdbcType=VARCHAR}");
        }
        
        if (record.getYoungOrOld() != null) {
            VALUES("young_or_old", "#{youngOrOld,jdbcType=INTEGER}");
        }
        
        if (record.getJoinNum() != null) {
            VALUES("join_num", "#{joinNum,jdbcType=INTEGER}");
        }
        
        if (record.getIsPublic() != null) {
            VALUES("is_public", "#{isPublic,jdbcType=INTEGER}");
        }
        
        if (record.getTel() != null) {
            VALUES("tel", "#{tel,jdbcType=VARCHAR}");
        }
        
        if (record.getAddr() != null) {
            VALUES("addr", "#{addr,jdbcType=VARCHAR}");
        }
        
        if (record.getTraffic() != null) {
            VALUES("traffic", "#{traffic,jdbcType=VARCHAR}");
        }
        
        if (record.getCreatedTime() != null) {
            VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Unit record) {
        BEGIN();
        UPDATE("unit");
        
        if (record.getUserId() != null) {
            SET("user_id = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getKind() != null) {
            SET("kind = #{kind,jdbcType=INTEGER}");
        }
        
        if (record.getTitle() != null) {
            SET("title = #{title,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }
        
        if (record.getImage() != null) {
            SET("image = #{image,jdbcType=VARCHAR}");
        }
        
        if (record.getLatitude() != null) {
            SET("latitude = #{latitude,jdbcType=VARCHAR}");
        }
        
        if (record.getLongitude() != null) {
            SET("longitude = #{longitude,jdbcType=VARCHAR}");
        }
        
        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getAddress() != null) {
            SET("address = #{address,jdbcType=VARCHAR}");
        }
        
        if (record.getScope() != null) {
            SET("scope = #{scope,jdbcType=VARCHAR}");
        }
        
        if (record.getForm() != null) {
            SET("form = #{form,jdbcType=INTEGER}");
        }
        
        if (record.getLeastCourseNum() != null) {
            SET("least_course_num = #{leastCourseNum,jdbcType=INTEGER}");
        }
        
        if (record.getLeastPrice() != null) {
            SET("least_price = #{leastPrice,jdbcType=INTEGER}");
        }
        
        if (record.getPrice() != null) {
            SET("price = #{price,jdbcType=INTEGER}");
        }
        
        if (record.getMaxPerson() != null) {
            SET("max_person = #{maxPerson,jdbcType=INTEGER}");
        }
        
        if (record.getDate() != null) {
            SET("date = #{date,jdbcType=VARCHAR}");
        }
        
        if (record.getTimeLen() != null) {
            SET("time_len = #{timeLen,jdbcType=INTEGER}");
        }
        
        if (record.getTool() != null) {
            SET("tool = #{tool,jdbcType=VARCHAR}");
        }
        
        if (record.getYoungOrOld() != null) {
            SET("young_or_old = #{youngOrOld,jdbcType=INTEGER}");
        }
        
        if (record.getJoinNum() != null) {
            SET("join_num = #{joinNum,jdbcType=INTEGER}");
        }
        
        if (record.getIsPublic() != null) {
            SET("is_public = #{isPublic,jdbcType=INTEGER}");
        }
        
        if (record.getTel() != null) {
            SET("tel = #{tel,jdbcType=VARCHAR}");
        }
        
        if (record.getAddr() != null) {
            SET("addr = #{addr,jdbcType=VARCHAR}");
        }
        
        if (record.getTraffic() != null) {
            SET("traffic = #{traffic,jdbcType=VARCHAR}");
        }
        
        if (record.getCreatedTime() != null) {
            SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}